export default function (req, res) {
    const { query } = req;
  
    // Validate required query parameter 'orderId'
    if (!query.orderId) {
      return new Promise((resolve) => {
        resolve({
          code: 1,
          message: '缺少必需的查询参数：orderId',
        });
      });
    }
  
    // Define mock data sets
    const statuses = [1, 2, 3];
    const types = [1, 2];
    const reasonTypes = [1, 2, 3, 4, 5, 6];
  
    const generateMockRefundDetail = (orderId) => {
      const status = statuses[Math.floor(Math.random() * statuses.length)];
      const type = types[Math.floor(Math.random() * types.length)];
      const studentRefundAmount = parseFloat((Math.random() * 1000 + 50).toFixed(2));
      
      // Use the specified date format
      const createDate = new Date(Date.now() - Math.floor(Math.random() * 60) * 24 * 60 * 60 * 1000);
      const refundArrivalDate = status === 2 ? new Date(createDate.getTime() + Math.floor(Math.random() * 7) * 24 * 60 * 60 * 1000) : null;
      const formatDate = (date) => {
        if (!date) return null;
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
      };
  
      return {
        id: parseInt(orderId),
        refundNo: `RF${Math.floor(Math.random() * 90000000) + 10000000}`,
        status: status,
        type: type,
        studentRefundAmount: studentRefundAmount,
        refundArrivalTime: formatDate(refundArrivalDate),
        createTime: formatDate(createDate),
        reasonTypes: reasonTypes,
        reason: `这是退费ID ${orderId} 的模拟备注。`,
        operator: {
          id: Math.floor(Math.random() * 1000) + 1,
          name: `操作员${Math.floor(Math.random() * 10) + 1}`,
        },
      };
    };
  
    return new Promise((resolve) => {
      setTimeout(() => {
        // Return a single-item array for refund details
        const orderId = parseInt(query.orderId);
        const data = [generateMockRefundDetail(orderId)];
  
        resolve({
          code: 0,
          message: '成功！',
          data: data,
          timestamp: Date.now(),
          requestId: 'requestId_' + Math.random().toString(36).substring(2, 15),
          signature: 'signature_' + Math.random().toString(36).substring(2, 15),
        });
      }, 100);
    });
  }